package com.example.zhaojianxu.signin.englishStudy.study.view

import android.graphics.Color
import android.os.Bundle
import android.support.v4.app.Fragment
import android.support.v4.view.ViewPager
import android.view.View
import com.example.zhaojianxu.signin.R
import com.example.zhaojianxu.signin.bean.BaseActivity
import com.example.zhaojianxu.signin.englishStudy.study.StudyAdapter
import com.example.zhaojianxu.signin.englishStudy.study.model.StudyEntity
import kotlinx.android.synthetic.main.activity_study.*
import kotlinx.android.synthetic.main.common_title_bar.*

class StudyActivity : BaseActivity(), IStudyListener{

    var mAdapter: StudyAdapter? = null
    var mList: MutableList<Fragment> = mutableListOf()

    override fun initView() {
        initVP()
        common_setting.visibility = View.GONE
        common_setting.setOnClickListener {
            finish()
        }
        common_back.setOnClickListener {
            finish()
        }
    }

    private fun initVP() {
        mAdapter = StudyAdapter(supportFragmentManager, mList)
        activity_study_vp.adapter = mAdapter

        activity_study_vp.addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
            override fun onPageScrollStateChanged(p0: Int) {
            }

            override fun onPageScrolled(p0: Int, p1: Float, p2: Int) {
            }

            override fun onPageSelected(p0: Int) {
                if (p0 == mList.size - 1) {
                    common_setting.text = "结束"
                    common_setting.setTextColor(Color.WHITE)
                    common_setting.visibility = View.VISIBLE
                } else {
                    common_setting.visibility = View.GONE
                }
            }
        })
    }

    override fun initData() {

        for (it in 0..5) {
            val fragment = StudyFragment()
            val bundle = Bundle()
            bundle.putInt("position",it)
            bundle.putSerializable("model",StudyEntity())
            fragment.arguments = bundle

            mList.add(fragment)
        }

        mAdapter?.notifyDataSetChanged()

        //请求 根据传入参数不同，请求不同的参数

    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_study)
    }

    override fun success() {

    }

    override fun failed() {
    }

}
